unit TrocaSenhaRecordFr;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls, ComCtrls, DBCtrls, ActnList, Buttons, MainRecordFr;

type

  { TTrocaSenhaRecordFrame }

  TTrocaSenhaRecordFrame = class(TMainRecordFrame)
    AtivoDBRadio: TDBRadioGroup;
    DBEdit4: TDBEdit;
    GroupBox1: TGroupBox;
    IDUsuarioDBEdit: TDBEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    nome_pessoa: TDBEdit;
    SenhaGroupBox: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    SenhaNovaEdit: TEdit;
    SenhaAtualEdit: TEdit;
    SenhaConfirmaEdit: TEdit;
    procedure CancelarActionExecute(Sender: TObject);
    procedure FecharActionExecute(Sender: TObject);
    procedure InserirActionExecute(Sender: TObject);
    procedure SalvarActionExecute(Sender: TObject);
    procedure ControlaBotoes(); override;
    constructor Create(TheOwner: TComponent); override;
  private
    { private declarations }
    Acao: string;
  public
    { public declarations }
  end;

implementation

uses
  Initializator, TrocaSenhaDM, MainFr, MainFm;

{ TTrocaSenhaRecordFrame }

procedure TTrocaSenhaRecordFrame.InserirActionExecute(Sender: TObject);
begin
  Acao := 'I';
  SenhaGroupBox.Enabled := True;
  ControlaBotoes();
end;

procedure TTrocaSenhaRecordFrame.SalvarActionExecute(Sender: TObject);
begin
  if SenhaNovaEdit.Text <> SenhaConfirmaEdit.Text then begin
    ShowMessage('Senha de Confirmação está diferente!');
  end else if (TrocaSenhaData.ConfereSenha(MainForm.Usuario, SenhaAtualEdit.Text)) then begin
    TrocaSenhaData.AlteraSenha(MainForm.Usuario,SenhaNovaEdit.Text);
    ShowMessage('Senha Alterada com Sucesso!');
    Acao := 'S';
    ControlaBotoes();
  end else begin
    ShowMessage('Senha Atual Inválida!');
  end;
end;

procedure TTrocaSenhaRecordFrame.ControlaBotoes();
var
  I: integer;
begin
  SenhaAtualEdit.Text:='';
  SenhaConfirmaEdit.Text:='';
  SenhaNovaEdit.Text:='';
  RecordDBNavigator.Enabled := False;
  for I := 0 to RecordActionList.ActionCount - 1 do begin
    TAction(RecordActionList.Actions[i]).Enabled := False;
  end;
  FecharAction.Enabled := True;
  InserirAction.Enabled := True;
  if (Acao = 'S') or (Acao = 'C') then begin
    InserirAction.Enabled := True;
    SalvarAction.Enabled := False;
    CancelarAction.Enabled := False;
  end else if Acao = 'I' then begin
    InserirAction.Enabled := False;
    SalvarAction.Enabled := True;
    CancelarAction.Enabled := True;
  end;
end;

constructor TTrocaSenhaRecordFrame.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
end;

procedure TTrocaSenhaRecordFrame.CancelarActionExecute(Sender: TObject);
begin
  Acao := 'C';
  SenhaGroupBox.Enabled := False;
  ControlaBotoes();
end;

procedure TTrocaSenhaRecordFrame.FecharActionExecute(Sender: TObject);
begin
  TheControl.BackFrame();
end;

initialization
  {$I trocasenharecordfr.lrs}

end.




